package com.example.ai.controller;

import com.example.ai.service.StatisticsService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/statistics")
@RequiredArgsConstructor
public class StatisticsController {

    private final StatisticsService statisticsService;

    @GetMapping
    public ResponseEntity<Map<String, Object>> getStatistics(Authentication authentication) {
        String username = authentication.getName();
        Map<String, Object> statistics = statisticsService.getUserStatistics(username);
        return ResponseEntity.ok(statistics);
    }

    @PostMapping("/update")
    public ResponseEntity<?> updateStatistics(
            Authentication authentication,
            @RequestParam boolean correct,
            @RequestParam long timeSpent) {
        String username = authentication.getName();
        statisticsService.updateStatistics(username, correct, timeSpent);
        return ResponseEntity.ok().build();
    }
} 